package com.cy.pj.arithmetic.service;

import com.cy.pj.common.exception.ServiceException;
import org.springframework.stereotype.Service;

/**
 * @author Cx
 * @stage secondStageOfWeb
 * @creat 2020-11-09 15:13
 */
@Service
public class ArithmeticService {

    public int sum(int a, int b) {
        if (a < 0 || b < 0)
            throw new ServiceException("参数值不能为负值");
        return a + b;
    }

    public Integer doSum(Integer... nums) {
        Integer sum = 0;
        if (nums == null || nums.length == 0)
            throw new ServiceException("数组不能为空值");
        for (Integer singleValue :
                nums) {
            sum += singleValue;
        }
        return sum;
    }

}
